<?php

namespace app\api\controller;

use app\common\controller\Api;
use EasyWeChat\Factory;
use app\api\controller\My;
use fast\Http;

/**
 * 首页接口
 */
class Qsy extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];



    /**
     * xcx配置
     */
    public  function config_xcx()
    {
        $config_open = [
            'app_id'   => 'wxc4cf6d2f0e8717d1',
            'secret'   => '589cdea3a64554e3400316714c7583b3',
            //'response_type' => 'object',
            // 'token' => 'f1c242gdfhggfhghgh',
            // 'aes_key' => 'hPM9UCsg3Oie1yHeuO821z3DRhQBmYnFigLY1D23csk',
        ];
        return $config_open;
    }

    public  function login()
    {
        $code = $this->request->request('code');
        $config = $this->config_xcx();
        $app = Factory::miniProgram($config);
        $rst = $app->auth->session($code);
        return $this->success('', $rst);
    }

    public function getInfo()
    {
        $code = $this->request->request('code');


        $config = $this->config_xcx();
        $app = Factory::miniProgram($config);
        $rst = $app->auth->session($code);
        if (!isset($rst['openid'])) {
            return $this->error('请求异常');
        }


        $url = $this->request->request('url');
        $rst =  http::post('https://v2.alapi.cn/api/video/url?token=b4jtnsX2JAjoMkbAbDYS&url=' . $url);

        $eee = json_decode($rst, true);
        $this->success('成功', $eee['data']);
    }
    public function setting()
    {
        $eee = [
            'bannle' => [
                [
                    'title' => 'https://s1.ax1x.com/2022/08/17/vD37YF.png'
                ]

            ],
            'swiperList' => [
                'title' => 'https://s1.ax1x.com/2022/08/17/vD37YF.png'
            ],
            'wxConfig' => [
                'notice' => '欢迎使用去水印免费小工具，小程序持续更新中...',
                'is_ad' => 0
            ]
        ];
        $this->success('成功', $eee);
    }

    public  function userdetail()
    {
        $token = $this->request->request('code');
        $eee = [
            'nickName' => '',
            'avatarUrl' => 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

        ];
        $this->success('成功', $eee);
    }
}
